package com.egao.common.publicly;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.publicly.entity.PubliclyCareerVO;
import com.egao.common.publicly.entity.PubliclyMutualCompanyVO;
import com.egao.common.publicly.service.PubliclyMutualService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 校内双选会
 *
 * @author pyx
 */
@Api(tags = "校内双选会")
@RestController
@RequestMapping("${api}")
public class PubliclyMutualController extends BaseController {
    @Autowired
    private PubliclyMutualService publiclyMutualService;

    @ApiOperation("列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页条数", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "title", value = "标题", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "companyName", value = "举办方", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "holdTime", value = "举办时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "holdAddress", value = "举办地点", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "时间是否已过，0否，1是", required = false, dataType = "Integer", paramType = "query"),
    })
    @GetMapping("/publicly/mutual/list")
    public PageResult<PubliclyCareerVO> list(HttpServletRequest request) {
        PageParam<PubliclyCareerVO> pageParam = new PageParam<>(request);
        return new PageResult<>(publiclyMutualService.listPage(pageParam), pageParam.getTotal());
    }

    @ApiOperation("详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "query"),
    })
    @OperLog(value = "校内双选会", desc = "查询详情")
    @GetMapping("/publicly/mutual/get")
    public JsonResult get(Integer id) {
        if (id == null) {
            return JsonResult.error("没有找到相应信息");
        }
        return publiclyMutualService.getId(getLoginUserId(), id);
    }

    @ApiOperation("双选会招聘信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mutualId", value = "双选会id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, dataType = "int", paramType = "query"),
    })
    @GetMapping("/publicly/mutual/apply/get")
    public JsonResult getApply(Integer mutualId,Integer companyId){
        if(mutualId == null){
         return JsonResult.error("没有找到相应信息");
        }
        if(companyId == null){
            return JsonResult.error("没有找到该公司");
        }

        return publiclyMutualService.getApply(mutualId,companyId);
    }

}
